import {
	defineStore
} from 'pinia';
import {
	category,storenamedetal
} from "@/api/home.js"
export const useAppStore = defineStore('app', {
	state: () => {
		return {
			// 状态栏高度
			statusBarHeight: 47,
			// 导航栏高度
			navigationBarHeight: 48,
			// 胶囊按钮高度
			menuButtonHeight: 32,
			// 导航栏和状态栏高度
			navigationBarAndStatusBarHeight: 0,
		}
	},
	actions: {
		setCustomBar() {
			//计算导航栏高度
			const {
				statusBarHeight,
				platform
			} = uni.getSystemInfoSync()
			const {
				top,
				height
			} = wx.getMenuButtonBoundingClientRect()
			// 状态栏高度
			this.statusBarHeight = statusBarHeight

			// 胶囊按钮高度 一般是32 如果获取不到就使用32
			this.menuButtonHeight = height ? height : 32

			// 判断胶囊按钮信息是否成功获取
			if (top && top !== 0 && height && height !== 0) {
				// 导航栏高度
				this.navigationBarHeight = (top - statusBarHeight) * 2 + height
			} else {
				//获取失败使用默认的高度
				this.navigationBarHeight = platform === 'android' ? 48 : 40
			}

			this.navigationBarAndStatusBarHeight = this.statusBarHeight + this.navigationBarHeight
		},
		getcategory(id, deliveryPrice,storeId,type) {
			storenamedetal({
				storeId: id
			}).then(res => {
				if(res.code==200){
					category({
						storeId: id
					}).then(res => {
						if (res.code == 200) {
							if (res.result.hasSub == false) {
								uni.navigateTo({
									url: "/page_index/secondstore?id=" + id + '&deliveryPrice=' +
										deliveryPrice + '&type=' + type + '&cq=' + storeId
								})
							} else {
								uni.navigateTo({
									url: "/page_index/storedetals?id=" + id + '&deliveryPrice=' +
										deliveryPrice + '&type=' + type + '&cq=' + storeId
								})
							}
						}
					})
				}
			})
		
		}

	}
})